﻿<phone:PhoneApplicationPage
                            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                            xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
                            xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
                            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                            xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
                            xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
                            xmlns:local="clr-namespace:ScheduleMVVM"
                            xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
                            xmlns:Command="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WP71"
                            xmlns:mec="clr-namespace:Microsoft.Expression.Controls;assembly=Microsoft.Expression.Controls"
                            xmlns:ec="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions"
                            xmlns:Coding4Fun_Phone_Controls="clr-namespace:Coding4Fun.Phone.Controls;assembly=Coding4Fun.Phone.Controls"
                            xmlns:ext="clr-namespace:WPExtensions;assembly=WPExtensions"
                            SupportedOrientations="Portrait"
                            Orientation="Portrait"
                            mc:Ignorable="d"
                            d:DesignWidth="480"
                            d:DesignHeight="800"
                            x:Class="ScheduleMVVM.MainPage"
                            toolkit:TiltEffect.IsTiltEnabled="True"
                            >
    <!-- Resources valid throughout the page -->
    <phone:PhoneApplicationPage.Resources>
        <DataTemplate x:Key="RouteTileTemplate">
            <Grid>
                <toolkit:HubTile HorizontalAlignment="Center" VerticalAlignment="Center" Title="{Binding Title, Mode=OneWay}" Message="{Binding RouteString, Mode=OneWay}" Margin="5" toolkit:TiltEffect.SuppressTilt="True">
                	<toolkit:HubTile.Background>
                		<SolidColorBrush Color="{StaticResource Mango Leaf Green}"/>
                	</toolkit:HubTile.Background>
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="Tap">
                            <ec:NavigateToPageAction TargetPage="/RoutePage.xaml"/>
                            <Command:EventToCommand Command="{Binding RoutePageShowCommand, Mode=OneWay}"/>
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                    <toolkit:ContextMenuService.ContextMenu>
                        <toolkit:ContextMenu>
                            <toolkit:MenuItem Header="edit" Foreground="Black">
                                <i:Interaction.Triggers>
                                    <i:EventTrigger EventName="Tap">
                                        <Command:EventToCommand Command="{Binding EditFavouriteCommand}"/>
                                    </i:EventTrigger>
                                </i:Interaction.Triggers>
                            </toolkit:MenuItem>
                            <toolkit:MenuItem Header="delete" Foreground="Black">
                                <i:Interaction.Triggers>
                                    <i:EventTrigger EventName="Tap">
                                        <Command:EventToCommand Command="{Binding DeleteFavouriteCommand}"/>
                                    </i:EventTrigger>
                                </i:Interaction.Triggers>
                            </toolkit:MenuItem>
                            <toolkit:MenuItem Header="pin to start" Foreground="Black">
                                <i:Interaction.Triggers>
                                    <i:EventTrigger EventName="Tap">
                                        <Command:EventToCommand Command="{Binding PinEntryCommand}"/>
                                    </i:EventTrigger>
                                </i:Interaction.Triggers>
                            </toolkit:MenuItem>
                        </toolkit:ContextMenu>
                    </toolkit:ContextMenuService.ContextMenu>
                </toolkit:HubTile>
            </Grid>
        </DataTemplate>
        <mec:IsArrangedToScaleConverter x:Key="IsArrangedToScaleConverter"/>
        <Style x:Key="NoSelectionTemplate" TargetType="mec:PathListBoxItem">
            <Setter Property="HorizontalContentAlignment" Value="Left"/>
            <Setter Property="VerticalContentAlignment" Value="Top"/>
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="mec:PathListBoxItem">
                        <Grid Background="{TemplateBinding Background}" RenderTransformOrigin="0.5,0.5">
                            <Grid.RenderTransform>
                                <TransformGroup>
                                    <ScaleTransform ScaleY="{Binding IsArranged, Converter={StaticResource IsArrangedToScaleConverter}, RelativeSource={RelativeSource TemplatedParent}}" ScaleX="{Binding IsArranged, Converter={StaticResource IsArrangedToScaleConverter}, RelativeSource={RelativeSource TemplatedParent}}"/>
                                    <SkewTransform/>
                                    <RotateTransform Angle="{Binding OrientationAngle, RelativeSource={RelativeSource TemplatedParent}}"/>
                                    <TranslateTransform/>
                                </TransformGroup>
                            </Grid.RenderTransform>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal"/>
                                    <VisualState x:Name="MouseOver"/>
                                    <VisualState x:Name="Disabled">
                                        <Storyboard>
                                            <DoubleAnimation Duration="0" To=".55" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="contentPresenter"/>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Rectangle x:Name="fillColor" Fill="#FFBADDE9" IsHitTestVisible="False" Opacity="0" RadiusY="1" RadiusX="1"/>
                            <Rectangle x:Name="fillColor2" Fill="#FFBADDE9" IsHitTestVisible="False" Opacity="0" RadiusY="1" RadiusX="1"/>
                            <ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}"/>
                            <Rectangle x:Name="FocusVisualElement" RadiusY="1" RadiusX="1" Stroke="#FF6DBDD1" StrokeThickness="1" Visibility="Collapsed"/>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <DataTemplate x:Key="PanoramaHeaderTemplate">
            <Grid>
                <TextBlock Text="{Binding}">
                	<TextBlock.Foreground>
                		<SolidColorBrush Color="{StaticResource Mango Leaf Green}"/>
                	</TextBlock.Foreground>
                </TextBlock>
            </Grid>
        </DataTemplate>

        <DataTemplate x:Key="FavouriteListBoxItemTemplate">
            <Grid Height="65">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="MouseLeftButtonDown">
                        <ec:NavigateToPageAction TargetPage="/RoutePage.xaml"/>
                        <Command:EventToCommand Command="{Binding}"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
                <TextBlock Margin="60,0,0,0" TextWrapping="Wrap" Text="{Binding Title}" d:LayoutOverrides="Width, Height" VerticalAlignment="Top" FontSize="24"/>
                <TextBlock Margin="70,35,0,0" TextWrapping="Wrap" Text="{Binding RouteString}" d:LayoutOverrides="Width, Height" Style="{StaticResource PhoneTextSubtleStyle}"/>
                <Image HorizontalAlignment="Left" VerticalAlignment="Top" Source="/icons/appbar.favs.rest.png" RenderTransformOrigin="0.5,0.5">
                    <Image.RenderTransform>
                        <CompositeTransform ScaleX="0.7" ScaleY="0.7"/>
                    </Image.RenderTransform>
                </Image>
            </Grid>
        </DataTemplate>
        <DataTemplate x:Key="SearchListBoxItemTemplate">
            <Grid Height="65">
                <TextBlock Margin="60,0,0,0" TextWrapping="Wrap" Text="search query" d:LayoutOverrides="Width, Height" VerticalAlignment="Top" FontSize="24"/>
                <TextBlock Margin="70,35,0,0" TextWrapping="Wrap" Text="{Binding RouteString}" d:LayoutOverrides="Width, Height" Style="{StaticResource PhoneTextSubtleStyle}"/>
                <Image Margin="0" HorizontalAlignment="Left" VerticalAlignment="Top" Source="/icons/appbar.feature.search.rest.png" RenderTransformOrigin="0.5,0.5">
                    <Image.RenderTransform>
                        <CompositeTransform ScaleX="0.7" ScaleY="0.7"/>
                    </Image.RenderTransform>
                </Image>
            </Grid>
        </DataTemplate>
        <Style x:Key="NoSelectionListBox" TargetType="ListBoxItem">
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="BorderBrush" Value="Transparent"/>
            <Setter Property="Padding" Value="0"/>
            <Setter Property="HorizontalContentAlignment" Value="Left"/>
            <Setter Property="VerticalContentAlignment" Value="Top"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListBoxItem">
                        <Border x:Name="LayoutRoot" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}">
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal"/>
                                    <VisualState x:Name="MouseOver"/>
                                    <VisualState x:Name="Disabled"/>
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="SelectionStates">
                                    <VisualState x:Name="Unselected"/>
                                    <VisualState x:Name="Selected"/>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <ContentControl x:Name="ContentContainer" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Foreground="{TemplateBinding Foreground}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    	<DataTemplate x:Key="FavouritesHeaderTemplate">
    		<Grid Width="450">
    			<TextBlock Text="{Binding}" HorizontalAlignment="Left">
    				<TextBlock.Foreground>
    					<SolidColorBrush Color="{StaticResource Mango Leaf Green}"/>
    				</TextBlock.Foreground>
    			</TextBlock>
    			<Coding4Fun_Phone_Controls:RoundButton Content="" HorizontalAlignment="Right" Margin="0,0,0,5" VerticalAlignment="Bottom" d:LayoutOverrides="Height" ImageSource="/icons/appbar.favs.rest.png">
    				<i:Interaction.Triggers>
    					<i:EventTrigger EventName="Click">
    						<ec:NavigateToPageAction TargetPage="/FavouritesPage.xaml"/>
    					</i:EventTrigger>
    				</i:Interaction.Triggers>
    				<Coding4Fun_Phone_Controls:RoundButton.Foreground>
    					<SolidColorBrush Color="#FF66AA2B"/>
    				</Coding4Fun_Phone_Controls:RoundButton.Foreground>
    				<Coding4Fun_Phone_Controls:RoundButton.BorderBrush>
    					<SolidColorBrush Color="{StaticResource Mango Leaf Green}"/>
    				</Coding4Fun_Phone_Controls:RoundButton.BorderBrush>
    			</Coding4Fun_Phone_Controls:RoundButton>
    		</Grid>
    	</DataTemplate>
    </phone:PhoneApplicationPage.Resources>
    <phone:PhoneApplicationPage.FontFamily>
        <StaticResource ResourceKey="PhoneFontFamilyNormal"/>
    </phone:PhoneApplicationPage.FontFamily>
    <phone:PhoneApplicationPage.FontSize>
        <StaticResource ResourceKey="PhoneFontSizeNormal"/>
    </phone:PhoneApplicationPage.FontSize>
    <phone:PhoneApplicationPage.Foreground>
        <StaticResource ResourceKey="PhoneForegroundBrush"/>
    </phone:PhoneApplicationPage.Foreground>
    <phone:PhoneApplicationPage.DataContext>
        <Binding Path="Main" Source="{StaticResource Locator}"/>
    </phone:PhoneApplicationPage.DataContext>
    <!-- Transition support -->
    <toolkit:TransitionService.NavigationInTransition>
        <toolkit:NavigationInTransition>
            <toolkit:NavigationInTransition.Backward>
                <toolkit:TurnstileTransition Mode="BackwardIn"/>
            </toolkit:NavigationInTransition.Backward>
            <toolkit:NavigationInTransition.Forward>
                <toolkit:TurnstileTransition Mode="ForwardIn"/>
            </toolkit:NavigationInTransition.Forward>
        </toolkit:NavigationInTransition>
    </toolkit:TransitionService.NavigationInTransition>
    <toolkit:TransitionService.NavigationOutTransition>
        <toolkit:NavigationOutTransition>
            <toolkit:NavigationOutTransition.Backward>
                <toolkit:TurnstileTransition Mode="BackwardOut"/>
            </toolkit:NavigationOutTransition.Backward>
            <toolkit:NavigationOutTransition.Forward>
                <toolkit:TurnstileTransition Mode="ForwardOut"/>
            </toolkit:NavigationOutTransition.Forward>
        </toolkit:NavigationOutTransition>
    </toolkit:TransitionService.NavigationOutTransition>
    <!--LayoutRoot contains the root grid where all other page content is placed-->
    <Grid x:Name="LayoutRoot">
    	<i:Interaction.Triggers>
    		<i:EventTrigger>
    			<Command:EventToCommand Command="{Binding OnLoadCommand, Mode=OneWay}"/>
    		</i:EventTrigger>
    	</i:Interaction.Triggers>
    	<Grid.Background>
    		<SolidColorBrush Color="{StaticResource Crisp Sheets}"/>
    	</Grid.Background>
        <controls:Panorama Margin="0" Title="{Binding ApplicationTitle, Mode=OneWay}" TabIndex="{Binding SelectedIndex, Mode=TwoWay}" HeaderTemplate="{StaticResource PanoramaHeaderTemplate}">
            <controls:PanoramaItem Header="{Binding FavouritesTitle}" Width="600" Orientation="Horizontal" HeaderTemplate="{StaticResource FavouritesHeaderTemplate}">
                <Grid Width="600">
                    <mec:PathListBox x:Name="pathListBox" ItemTemplate="{StaticResource RouteTileTemplate}" ItemsSource="{Binding Favourites}" ItemContainerStyle="{StaticResource NoSelectionTemplate}" Width="600">
                        <mec:PathListBox.LayoutPaths>
                            <mec:LayoutPath SourceElement="{Binding ElementName=path}"/>
                            <mec:LayoutPath SourceElement="{Binding ElementName=path1}"/>
                            <mec:LayoutPath SourceElement="{Binding ElementName=path2}"/>
                        </mec:PathListBox.LayoutPaths>
                    </mec:PathListBox>
                    <Path x:Name="path" Data="M0,0 L0,248 z" HorizontalAlignment="Left" Margin="100,100,0,180" Stretch="Fill" Width="0"/>
                    <Path x:Name="path1" Data="M0,0 L0,248 z" HorizontalAlignment="Left" Margin="300,100,0,180" Stretch="Fill" Width="0"/>
                    <Path x:Name="path2" Data="M0,0 L0,248 z" HorizontalAlignment="Left" Margin="500,100,0,180" Stretch="Fill" Width="0"/>
                </Grid>
            </controls:PanoramaItem>
            <controls:PanoramaItem Header="{Binding RecentTitle}">
                <Grid>
                    <ListBox ItemsSource="{Binding Recent}" Margin="10,0,0,0" ItemContainerStyle="{StaticResource NoSelectionListBox}">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <local:RecentListBoxTemplateSelector Content="{Binding}">
                                    <local:RecentListBoxTemplateSelector.FavouritesEntryStyle>
                                        <DataTemplate>
                                            <ListBoxItem>
                                                <i:Interaction.Triggers>
                                                    <i:EventTrigger EventName="Tap">
                                                        <ec:NavigateToPageAction TargetPage="/RoutePage.xaml"/>
                                                        <Command:EventToCommand Command="{Binding RoutePageShowCommand}"/>
                                                    </i:EventTrigger>
                                                </i:Interaction.Triggers>
                                                <Grid Height="65">
                                                    <TextBlock Margin="60,0,0,0" TextWrapping="Wrap" Text="{Binding Title}" d:LayoutOverrides="Width, Height" VerticalAlignment="Top" FontSize="24"/>
                                                    <TextBlock Margin="70,35,0,0" TextWrapping="Wrap" Text="{Binding RouteString}" d:LayoutOverrides="Width, Height" Style="{StaticResource PhoneTextSubtleStyle}"/>
                                                    <Image HorizontalAlignment="Left" VerticalAlignment="Top" Source="/icons/appbar.favs.rest_mod.png" RenderTransformOrigin="0.5,0.5">
                                                        <Image.RenderTransform>
                                                            <CompositeTransform ScaleX="0.7" ScaleY="0.7"/>
                                                        </Image.RenderTransform>
                                                    </Image>
                                                </Grid>
                                            </ListBoxItem>
                                        </DataTemplate>
                                    </local:RecentListBoxTemplateSelector.FavouritesEntryStyle>
                                    <local:RecentListBoxTemplateSelector.SearchEntryStyle>
                                        <DataTemplate>
                                            <ListBoxItem>
                                                <i:Interaction.Triggers>
                                                    <i:EventTrigger EventName="Tap">
                                                        <ec:NavigateToPageAction TargetPage="/RoutePage.xaml"/>
                                                        <Command:EventToCommand Command="{Binding RoutePageShowCommand}"/>
                                                    </i:EventTrigger>
                                                </i:Interaction.Triggers>
                                                <Grid Height="65">
                                                    <TextBlock Margin="60,0,0,0" TextWrapping="Wrap" Text="{Binding Main.SearchQueryString, Source={StaticResource Locator}}" d:LayoutOverrides="Width, Height" VerticalAlignment="Top" FontSize="24"/>
                                                    <TextBlock Margin="70,35,0,0" TextWrapping="Wrap" Text="{Binding RouteString}" d:LayoutOverrides="Width, Height" Style="{StaticResource PhoneTextSubtleStyle}"/>
                                                    <Image Margin="0" HorizontalAlignment="Left" VerticalAlignment="Top" Source="/icons/appbar.feature.search.rest_mod.png" RenderTransformOrigin="0.5,0.5">
                                                        <Image.RenderTransform>
                                                            <CompositeTransform ScaleX="0.7" ScaleY="0.7"/>
                                                        </Image.RenderTransform>
                                                    </Image>
                                                </Grid>
                                            </ListBoxItem>
                                        </DataTemplate>
                                    </local:RecentListBoxTemplateSelector.SearchEntryStyle>
                                </local:RecentListBoxTemplateSelector>
                            </DataTemplate>
                        </ListBox.ItemTemplate>

                    </ListBox>
                </Grid>
            </controls:PanoramaItem>
        </controls:Panorama>
        <ext:AdvancedApplicationBar HorizontalAlignment="Left" Height="100" VerticalAlignment="Top" Width="100" BackgroundColor="{StaticResource Twitter Blue}">
        	<ext:AdvancedApplicationBarIconButton Height="100" Text="{Binding Search, Mode=OneWay}" IconUri="/icons/appbar.feature.search.rest.png" Command="{Binding SearchCommand, Mode=OneWay}"/>
        	<ext:AdvancedApplicationBarMenuItem Height="100" Text="{Binding RateAppBarMenuItemString}" Command="{Binding MarketplaceReviewCommand}"/>
        	<ext:AdvancedApplicationBarMenuItem Height="100" Text="{Binding AboutAppBarMenuItemString, Mode=OneWay}" Command="{Binding AboutCommand, Mode=OneWay}"/>
        </ext:AdvancedApplicationBar>
    </Grid>

</phone:PhoneApplicationPage>